#d0 is the distribution on the right, with the greater mean #dz is the distribution on the left, with the lower mean #d0=density(z$calf.ratio[6,1,,]) #dz=density(z$calf.ratio[6,2,,]) # # #lower=calf.ci[1] #upper=calf.ci[2] #type="between" #manage_plot(z.0=z$phi[6,1,,], z.treat=z$phi[6,5,,], lower=.08, type="below",label= "Probability of infection", panel="A", xlim=c(0,.8)) manage_plot=function(z.0, z.treat,upper=NA, lower=NA, type, label,panel, xlim){ d0=density(z.0) dz=density(z.treat) x0=as.vector(d0$x) y0=as.vector(d0$y) xz=as.vector(dz$x) yz=as.vector(dz$y) plot(x0,y0,xlab=label, main=panel,typ="l",ylim=c(0,1.3*max(dz$y)), lwd=2, ylab="Density", col="grey") lines(xz,yz, lwd=2, col="black") if(type == "between"){ m = cbind(x0,y0) m=m[m[,1] > lower,] M=m[m[,1]< upper,] xx=c(M[,1],rev(M[,1])) yy=c(M[,2],rep(0,length(M[,2]))) #the .99 is to prevent polygon from blocking the line for the pdf polygon(xx,yy,col=topo.colors(5,alpha=.3), border=NA) m = cbind(xz,yz) m=m[m[,1] > lower,] M2=m[m[,1]< upper,] xx=c(M2[,1],rev(M2[,1])) yy=c(M2[,2],rep(0,length(M2[,2]))) polygon(xx,yy,density=10,border=NA) abline(h=0) abline(v=lower, lty="dashed") abline(v=upper,lty="dashed") } if(type == "below"){ m = cbind(xz,yz) M=m[m[,1]< lower,] xx=c(M[,1],rev(M[,1])) yy=c(M[,2],rep(0,length(M[,2]))) polygon(xx,yy,density=10,border=NA) m = cbind(x0,y0) M2=m[m[,1]< lower,] xx=c(M2[,1],rev(M2[,1])) yy=c(M2[,2],rep(0,length(M2[,2]))) polygon(xx,yy,col=topo.colors(5,alpha=.3)) lines(xz,yz, lwd=2, col="black") abline(v=lower, lty="dashed") abline(h=0) } if(type == "above"){ m = cbind(x0,y0) M=m[m[,1] > upper,] xx=c(M[,1],rev(M[,1])) yy=c(M[,2],rep(0,length(M[,2]))) polygon(xx,yy,col=topo.colors(5,alpha=.3)) m = cbind(xz,yz) M2=m[m[,1] > upper,] xx=c(M2[,1],rev(M2[,1])) yy=c(M2[,2],rep(0,length(M2[,2]))) polygon(xx,yy,density=10,border=NA) lines(xz,yz, lwd=2, col="black") abline(v=upper, lty="dashed") abline(h=0) } } #end of function